package com.jn.erp.web.api.institution.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jn.erp.security.entity.SysRole;
import com.jn.erp.security.entity.SysUser;
import com.jn.erp.web.api.institution.entity.vo.EmployeeInfoDto;
import com.jn.erp.web.api.institution.entity.vo.EmployeeStudentDto;
import com.jn.erp.web.api.institution.entity.vo.EmployeeVo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <pre>
 *
 * </pre>
 *
 * @author sunjiyong
 * @since 2024/8/28 15:43
 */
@Mapper
public interface EmployeeMapper  extends BaseMapper<SysUser> {

    List<EmployeeVo> selectEmployeeList(EmployeeVo employeeVo);

    List<EmployeeVo> selectTeacherEmployees(EmployeeVo employeeVo);


    int existOtherOrg(EmployeeVo employeeVo);

    List<SysRole> employeeRoleList(SysRole sysRole);

    List<EmployeeVo> roleUserList(SysRole sysRole);


    //wx学员列表信息
    @Results(value = {
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "gender", column = "gender"),
            @Result(property = "familyList", column = "id", javaType = List.class,
                    many = @Many(select = "com.jn.erp.web.api.institution.mapper.EmployeeMapper.selectFamilyListByStudentId"))
    })
    @Select("   SELECT DISTINCT s.id,s.name,s.gender FROM t_student_class sc LEFT JOIN  t_student_class_rela cr ON sc.id =cr.class_id " +
            " INNER JOIN t_student s ON cr.student_id=s.id " +
            " WHERE sc.org_id=#{orgId} AND cr.org_id=#{orgId}  AND cr.deleted=0 AND sc.deleted=0  AND sc.teacher_id=#{teacherId} AND s.deleted=0 " +
            " AND s.org_id=#{orgId} ")
    List<EmployeeStudentDto> getTeacherStudentList(EmployeeVo employeeVo);

    List<EmployeeStudentDto> selectFamilyListByStudentId(@Param("id") Long id);

    List<EmployeeInfoDto> getTeacherClassList(EmployeeVo employeeVo);

    //员工包含学员数量列表信息
    @Results(value = {
            @Result(property = "id", column = "id"),
            @Result(property = "nickName", column = "nick_name"),
            @Result(property = "mobile", column = "mobile"),
            @Result(property = "num", column = "id", javaType = String.class,
                    many = @Many(select = "com.jn.erp.web.api.student.mapper.StudentMapper.selNum"))
    })
    @Select(" <script> SELECT u.id , u.mobile , ou.nick_name ,ou.is_job FROM t_sys_role  r   " +
            " LEFT JOIN t_sys_user_role ur ON ur.role_id = r.role_id " +
            " LEFT JOIN t_sys_org_user ou ON ou.user_id = ur.user_id   " +
            " INNER JOIN t_sys_user u ON u.id=ur.user_id " +
            " WHERE role_key IN('educational','sales','leader') AND ur.org_id = #{orgId} AND ou.org_id = #{orgId} AND ou.deleted=0 " +
            "         <if test=\"wxParam != null and wxParam != ''\"> " +
            "            AND ( ou.nick_name like concat('%', #{wxParam}, '%') or u.mobile like concat('%', #{wxParam}, '%')) " +
            "        </if> " +
            " GROUP BY u.id " +
            " </script>")
    List<EmployeeVo> selectUnifyListStaff(EmployeeVo employeeVo);

    List<EmployeeVo> followPeopleList(@Param("employeeVo") EmployeeVo employeeVo);

    List<EmployeeVo> managerList(@Param("employeeVo") EmployeeVo employeeVo);

    List<EmployeeVo> teacherList(@Param("employeeVo") EmployeeVo employeeVo);

    List<EmployeeVo> managerJobList(@Param("employeeVo") EmployeeVo employeeVo);




    List<EmployeeVo> peopleJobList(@Param("employeeVo") EmployeeVo employeeVo);

    List<EmployeeVo> performanceList(@Param("employeeVo") EmployeeVo employeeVo);
}
